/**
 * 
 */
package me.myachievements.web.goal;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import org.apache.wicket.Session;
import org.apache.wicket.datetime.DateConverter;
import org.apache.wicket.datetime.StyleDateConverter;
import org.apache.wicket.extensions.markup.html.form.DateTextField;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.ListChoice;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.validation.validator.MinimumValidator;
import org.apache.wicket.validation.validator.StringValidator;

import me.myachievements.persistence.goal.Goal;
import me.myachievements.persistence.goal.GoalPersistenceManager;
import me.myachievements.web.administration.account.AccountListPage;

import me.myachievements.persistence.goal.*;

/**
 * @author besseym
 *
 */
public abstract class GoalForm extends Form<Goal> {
	
//	@SpringBean(name="dateConverter")
//	private DateConverter dateConverter;
	
	@SpringBean(name="goalPersistenceManager")
	GoalPersistenceManager goalPersistenceManager;

	/**
	 * Constructor
	 * @param id
	 * @param target
	 */
	public GoalForm(String id, String legend, Goal goal) {
		super(id, new CompoundPropertyModel<Goal>(goal));
		addComponents(legend);
	}
	
	/**
	 * Constructor
	 * @param id
	 * @param iModel
	 */
	public GoalForm(String id, String legend, IModel<Goal> iModel){
		super(id, new CompoundPropertyModel<Goal>(iModel));
		addComponents(legend);
	}
	
	/**
	 * Add Form components
	 */
	private void addComponents(String legend){
		
		add(new Label("form_legend", legend));
		
		add(new CheckBox("exposed"));
		add(new TextField<Long>("rank").setRequired(true).add(new MinimumValidator<Long>(0L)));
		add(new TextField<String>("title").setRequired(true).add(StringValidator.maximumLength(100)));
		add(new TextArea<String>("description").add(StringValidator.maximumLength(500)));
		
		Locale locale = Session.get().getLocale();
		DateConverter dateConverter = new StyleDateConverter("M-", false);
		String datePattern = dateConverter.getDatePattern();
		add(new DateTextField("completeBy", datePattern));
		add(new Label("datePattern", datePattern));
		
		List<PriorityEnum> priorities = Arrays.asList(PriorityEnum.values());
		add(new ListChoice<PriorityEnum>("priority", priorities));
	}

}
